import $ from '../jquery/jquery.min.js'
const token = localStorage.token;
if (token) {
    $.ajaxSetup({
        headers: {//请求头
            'Authorization': token
        },
        error(err) {
            if (err.status == 401) {
                // alert('登录已过期，请重新登录');//别打开！有bug，不改了
                location.href = '../login.html';
            }
        }
    })
} else {
    alert("你还没登录，请先登录");
    location.href = '../login.html';
}



export default function ajax({ url, type = 'GET', data = {}, success } = {}) {
    $.ajax({
        url: 'http://localhost:3100' + url,
        data,
        type,
        // traditional:true,
        success(res) {
            success(res);
        }
    })
}
